<template>
    <h2>用户注册</h2>
    <table>
        <tr>
            <td>
                用户名:
            </td>
            <td>
                <input type="text" v-model="UName" id="UName">
            </td>
        </tr>
        <tr>
            <td>
                密码:
            </td>
            <td>
                <input type="password" v-model="UPass" id="UPass">
            </td>
        </tr>
        <tr>
            <td>
                <input type="button" @click="Regist" value="注册">
            </td>
        </tr>
    </table>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import axios from 'axios'

const UName = ref("");
const UPass = ref("");

const Regist = () => {
    if (!UName.value) {
        alert("用户名不能为空");
        return;
    }
    if (!UPass.value) {
        alert("密码不能为空");
        return;
    }
    axios.post('http://localhost:64994/api/Demo/LoginAdd', {
        UName: UName.value,
        UPass: UPass.value

    })
        .then(res => {
            if (res.data == -1) {
                alert("用户已存在");
                return;
            }
            if (res.data > 0) {
                alert("登录成功");
                location.href = '/Login'
                return;
            }
            else {
                alert("登录失败");
                return;
            }
        })
        .catch(error => {
            console.log(error)
        })
}
</script>